package com.ddwl.order.dao;

import com.alibaba.fastjson.JSON;
import com.ddwl.common.dao.TkDao;
import com.ddwl.common.exception.GlobalException;
import com.ddwl.order.dao.mapper.OrderPhaseMapper;
import com.ddwl.order.dao.model.OrderPay;
import com.ddwl.order.dao.model.OrderPhase;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 订单阶段付款表(OrderPhase)表数据库访问层
 *
 * @author makejava
 * @since 2020-06-02 14:53:23
 */
@Repository
@Slf4j
public class OrderPhaseDao extends TkDao<OrderPhaseMapper, OrderPhase> {



    public List<OrderPhase> queryOrderPhases(List<String> orderIds){
        Example example = getExample();
        example.and().andIn("orderNo",orderIds);
        return baseMapper.selectByExample(example);
    }

    /**
     * 更新子订单付款状态
     * @param update
     * @param masterOrderId
     * @return
     */
    public void updateCompletePayment(OrderPhase update, String masterOrderId){
        Example example = new Example(OrderPhase.class);
        example.and().andEqualTo("masterOrderId",masterOrderId);
        int i = baseMapper.updateByExampleSelective(update, example);
        if(i<1){
            log.error("订单状态更新异常 orderNo={}", JSON.toJSONString(masterOrderId));
            throw new GlobalException("订单状态更新异常");
        }
    }
}